package cn.gift.exception;

import org.springframework.util.ObjectUtils;

/**
 * @description: BusinessAssert
 * @date: 2023/4/25 14:36
 * @author: ZhaoLc
 * @version: 1.0
 */
public class BusinessAssert {

    public static void isNull(Object obj,String message){
        if(obj==null) {
            throw new BusinessException(message);
        }
    }

    public static void isNotNull(Object obj,String message){
        if(obj!=null) {
            throw new BusinessException(message);
        }
    }

    public static void isEq(String str1, String str2, String message){
        if(!str1.equals(str2)) {
            throw new BusinessException(message);
        }
    }



    //////////////////////////////////////////////////////////////////////////////

    public static void isNull(Object obj,ErrorCode errorCode){
        if(obj==null) {
            throw new BusinessException(errorCode.getMessage(),errorCode.getCode());
        }
    }

    public static void isNotNull(Object obj,ErrorCode errorCode){
        if(obj!=null) {
            throw new BusinessException(errorCode.getMessage(),errorCode.getCode());
        }
    }

    public static void isEq(String str1, String str2,ErrorCode errorCode){
        if(!str1.equals(str2)) {
            throw new BusinessException(errorCode.getMessage(),errorCode.getCode());
        }
    }

    public static void isExist(Integer num, ErrorCode errorCode){
        if(num>0) {
            throw new BusinessException(errorCode.getMessage(),errorCode.getCode());
        }
    }

    public static void isExist(Object object, ErrorCode errorCode){
        if(ObjectUtils.isEmpty(object)) {
            throw new BusinessException(errorCode.getMessage(),errorCode.getCode());
        }
    }
}
